package Threadprojects.pro1_matrix.row;

import java.util.ArrayList;

public class RowMulitply {
    public static void multiply(double[][] m1, double[][] m2, double[][] rs) {
        ArrayList<Thread> list = new ArrayList<>();
        int m1Rows = m1.length;
        int m1Cols = m1[0].length;
        int m2Cols = m2[0].length;

        for (int i = 0; i < m1Rows; i++) {
            //把每一行的计算拆分未一次线程里面
                Thread t=new Thread(new RowTask(rs,m1,m2,i));
                t.start();
                list.add(t);
                if (list.size()%10==0){
                    waitForThread(list);
                }
        }

    }

    private static void waitForThread(ArrayList<Thread> list) {
        for (Thread thread : list) {
            try {
                thread.join();//等待方法结束再调用
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
